package com.dlxj.service.impl;

import java.util.Date;

import com.dlxj.dao.BaseDAO;
import com.dlxj.entity.Debugtask;
import com.dlxj.entity.Receiptdebug;
import com.dlxj.service.ReceiptDeBugService;
import com.dlxj.util.ConstClass;

public class ReceiptDeBugServiceImpl implements ReceiptDeBugService {

	BaseDAO baseDAO;

	@Override
	public int receiptTask(Receiptdebug receiptdebug) {
		receiptdebug.setState(ConstClass.TASK_AUDITING_MISSPASS);
		receiptdebug.setTime(new Date());
		receiptdebug.setUid(ConstClass.getCurrentUser().getId());
		baseDAO.saveOrUpdate(receiptdebug);
		Debugtask debugtask = (Debugtask) baseDAO.findById(Debugtask.class,
				receiptdebug.getDid());
		debugtask.setState(ConstClass.TASK_STATE_FINISH);
		baseDAO.update(debugtask);
		return ConstClass.ADD_SUCCESS;
	}

	public BaseDAO getBaseDAO() {
		return baseDAO;
	}

	public void setBaseDAO(BaseDAO baseDAO) {
		this.baseDAO = baseDAO;
	}

	@Override
	public int auditingReceipt(int id, String idea, int state) {
		Receiptdebug receiptdebug = (Receiptdebug) baseDAO.findById(
				Receiptdebug.class, id);
		receiptdebug.setIdea(idea);
		receiptdebug.setState(state);
		Debugtask debugtask = (Debugtask) baseDAO.findById(Debugtask.class,
				receiptdebug.getDid());
		if (state == ConstClass.TASK_AUDITING_PASS) {
			debugtask.setState(ConstClass.TASK_STATE_SURE);
			debugtask.setEndTime(new Date());
			baseDAO.update(debugtask);
		} else {
			debugtask.setState(ConstClass.TASK_STATE_EXECUTING);
			baseDAO.update(debugtask);
		}
		baseDAO.update(receiptdebug);
		return ConstClass.UPDATE_SUCCESS;
	}

}
